package com.xuecheng.content.interfaces.web;

import com.xuecheng.content.application.service.TeachplanApplication;
import com.xuecheng.content.application.vo.req.CourseAssociationMediaCmd;
import com.xuecheng.content.application.vo.req.TeachplanCreateCmd;
import com.xuecheng.content.domain.model.dto.TeachplanDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程计划 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@Api(value = "课程计划编辑接口", tags = "课程计划编辑接口")
@RestController
@RequestMapping("/teachplan")
public class TeachplanApi {

    @Autowired
    private TeachplanApplication teachplanApplication;

    @ApiOperation("查询课程计划树形结构")
    @ApiImplicitParam(value = "courseId", name = "课程Id", required = true, dataType = "Long", paramType = "path")
    @GetMapping("/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId) {
        return teachplanApplication.queryTreeNodes(courseId);
    }

    @ApiOperation("课程计划创建或修改")
    @PostMapping
    public void saveOrUpdateTeachplan(@RequestBody TeachplanCreateCmd teachplanCreateCmd){
        teachplanApplication.saveOrUpdateTeachplan(teachplanCreateCmd);
    }

    @ApiOperation("课程计划向下移动")
    @PostMapping("/movedown/{teachplanId}")
    public void moveDownTeachPlan(@PathVariable Long teachplanId){
        teachplanApplication.moveDownTeachPlan(teachplanId);
    }

    @ApiOperation("课程计划向上移动")
    @PostMapping("/moveup/{teachplanId}")
    public void moveUpTeachPlan(@PathVariable Long teachplanId){
        teachplanApplication.moveUpTeachPlan(teachplanId);
    }

    @ApiOperation("删除课程计划")
    @DeleteMapping("/{teachplanId}")
    public void deleteTeachPlan(@PathVariable Long teachplanId){
        teachplanApplication.deleteTeachPlan(teachplanId);
    }


    @ApiOperation("课程绑定媒资")
    @PostMapping("/association/media")
    public void associationMedia(@Validated @RequestBody CourseAssociationMediaCmd params){
        teachplanApplication.associationMedia(params);
    }

    @ApiOperation("删除课程绑定的媒资")
    @DeleteMapping("/association/media/{teachplanId}/{mediaId}")
    public void deleteAssociationMedia(@PathVariable("teachplanId") Long teachplanId, @PathVariable("mediaId") String mediaId){
        teachplanApplication.deleteAssociationMedia(teachplanId, mediaId);
    }

}
